<?php
namespace Api\Controller;
use Think\Controller;
use Qiniu\Auth as Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;
class IndexController extends CommonController {

    public function getNav()
    {
        $list = M('nav')->where(['wid'=>session('wid'),'status'=>1])->select();
        $this->ajaxReturn($list);
    }

    public function pian(){
        $a = M('wechat')->where(['wid'=>session('wid')])->find();
        $this->ajaxReturn($a);
    }
    public function weather(){
        $map['wid'] = session('wid');
        
        //$out = $this->ihttp_get("https://free-api.heweather.com/s6/weather/forecast?key=6baa4e9e59e44436b38407962919148c&location={$_GET['city']}", 0);
        $out = $this->ihttp_get("https://free-api.heweather.com/s6/weather/now?key=6baa4e9e59e44436b38407962919148c&location={$_GET['city']}");
        //$this->ajaxReturn($res);
        $td = json_decode($out, 1);
        $data = $td['HeWeather6'][0]['now'];

        $hour = date("H");
        $weeks = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
        $w = date('w');
        if($hour < 5 || $hour > 19){
            $t = 'n';
        }else{
            $t = 'd';
        }
        // print_r($data);

        $res = array(
            'city'=>$_GET['city'],
            'wendu'=>$data['tmp']."°",
            'tianqi'=>$data['cond_txt'],
            'code'=>$data['cond_code'],
            'code_img'=>'https://www.58zltc.com/Public/tianqi/'.$data['cond_code'].'.png',
            'date'=>date("Y-m-d"),
            'week'=>$weeks[$w],
            'type'=>'duoyun'
        );
        if(in_array($res['tianqi'], array('晴','少云','晴间多云','平静','热'))){
            $type = 'sunny';
        }elseif(preg_match('/风/', $res['tianqi'])){
            $type = 'wind';
        }elseif(preg_match('/雨/', $res['tianqi'])){
            $type = 'rain';
        }elseif(preg_match('/雪/', $res['tianqi'])){
            $type = 'snow';
        }elseif($res['tianqi'] == 'duoyun'){
            $type = 'duoyun';
        }else{
            $type = 'cloudy';
        }
        // $new = array('sunny','wind','rain','snow','duoyun','cloudy');
        // $num = rand(0,5);
        $res['type'] = $type;
        // echo $res;
        $this->ajaxReturn($res);
    }
    //独立小程序获取shopid
    public function getShopid()
    {
        $appid = I("appid");
        $wechat =M("wechat")->where(['appid'=>$appid])->find();
        if($wechat['shop_id']){
            $this->ajaxReturn(['code'=>0,'shop_id'=>$wechat['shop_id']]);
        }else{
            $this->ajaxReturn(['code'=>400,'msg'=>"访问失败"]);
        }
    }

    public function getAddressFilter(){
        $map['wid'] = session('wid');
        $wechat = M("Wechat")->where($map)->find();

        $where['city_code'] = $wechat['city'];
        $city = M("City")->where($where)->find();
        $where1['pid'] = $city['id'];
        $site_arr2 = M("City")->where($where1)->select();
        if($wechat['city'] == 0){
            $site_arr1_id = 0;
            $site_arr1 = "全国";
        }else{
            $site_arr1_id = $city['id'];
            $site_arr1 = $city["city_name"];
            if(!$site_arr2){
                $site_arr2 = array(array('id'=>0,'city_name'=>"全辖区"));
            }
        }

        $arr['title'] = '地区';
        $arr['is_show'] = false;
        $arr['list'] = array();
        $arr['list'][0] = array('id'=>0,'value'=>'全部', 'is_selected'=>true);
        $arr['list'][1] = array('id'=>$site_arr1_id,'value'=>$site_arr1, 'is_selected'=>false);
        foreach ($site_arr2 as $key => $value) {
            $arr['list'][1]['sub_list'][$key] = array('id'=>$value['id'] ,'value'=>$value['city_name'], 'is_selected'=>true);
        }
        return $this->ajaxReturn($arr);
    }

    public function adv (){
        $map['wid'] = session('wid');
        $map['type'] = $_GET['type'];
        $adv = M("adv")->where($map)->order("last_time desc")->getField('imgurl',true);
        $this->ajaxReturn($adv);
    }

    //
    public function getFlash(){
        $map['wid'] = session('wid');
        $map['type'] = 'home';
        $adv = M("adv")->where($map)->order("last_time desc")->getField('imgurl',true);
        $this->ajaxReturn($adv);
    }
// 首页数据生成方法
    public function index(){
        $array = [];
        if (isset($_GET['pageNum'])) {
            $page = (int)I('pageNum');
            // $page = ((int)$page) * 10;
        } else {
            $page = 0;
        }

        $map['wid'] = session('wid');
        $new['wechat'] = M('wechat')->where($map)->find();
        $map['is_pay'] = 1;

        //同城头条
        $list = M("InfoOrder")->where($map)->order("is_top desc,top_end_time desc,last_time desc")->limit(0, 100)->select();
        //更新地理位置
        if($_GET['openid']){
            $where['openid'] = $_GET['openid'];
            $member = M('member')->where(['wid'=>session('wid'),'openid'=>$_GET['openid']])->find();
            if(!($member['latitude']>0) && !($member['longitude']>0)){
                $save['latitude'] = I('la');
                $save['longitude'] = I('lo');
                M('member')->where(['wid'=>session('wid'),'openid'=>$_GET['openid']])->save();
            }

        }

        $eq['wid'] = session('wid');
        $eq['status'] = 1;
        $new['list'] = array();

        foreach ($list as $k => $v) {
            $eq['id'] = $v['info_id'];
            switch ($v['action']) {
                case 'job':
                    $vo = M("Job")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'job'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'job';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'house':
                    $vo = M("House")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'house'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'house';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'info':
                    $eq1['tp_info.wid'] = session('wid');
                    $eq1['tp_info.status'] = 1;
                    $eq1['tp_info.id'] = $v['info_id'];
                    $vo = M("Info")->join('tp_member ON tp_info.openid = tp_member.openid')->where($eq1)->field("tp_info.*, tp_member.nickname, tp_member.headimgurl")->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'info'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'info';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'pinche':
                    $vo = M("pinche")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'pinche'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'pinche';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;

                default:
                    # code...
                    break;
            }
        }
        //排序模板
        $arr = [];
        //查出对应模板的信息
        $wid = session('wid');
        $tuilist = M('tui_cate')->where(['status'=>1,'wid'=>session('wid')])->order('sort desc')->select();
        foreach($tuilist as $kk=>$vv){
            //查出有几条
            $count = M("tui")->where(['wid'=>$vv['wid'],'type'=>$vv['type'],'status'=>1])->count();
            $sum = M('tui_cate')->where(['wid'=>$vv['wid'],'type'=>$vv['type'],'status'=>1])->sum('count');
            //初始化分页变量
            if(session($vv['type'].'count')){
                //没有page时候 session($vv['type']) +上次的count
                $limit = session($vv['type']) + session($vv['type'].'count');
            }else{
                //有page时候 (page-1)*sum
                $limit  = 0 ;
                session($vv['type'],$limit);
                session($vv['type'].'count',$vv['count']);
            }
            //用户
            if($vv['type'] == "member"){
                $count2 = M('member')->alias("m")->where(['m.wid'=>session('wid')])->count();
                $sql ="SELECT count(*) AS c, q.openid,m.mid,m.nickname,m.headimgurl,m.user_monologue
                        FROM
                            tp_quan q
                        LEFT JOIN tp_member m ON m.openid = q.openid
                        WHERE q.wid = {$wid} AND m.nickname is not NULL
                        GROUP BY openid
                        ORDER BY
                        (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = q.wid AND type = '{$vv['type']}' and aid = m.mid )DESC, c DESC
                        LIMIT ".$limit.",{$vv['count']}";
                $news = M()->query($sql);
                foreach($news as $ko=>$vo){
                    //是否关注
                    $follow = M('quan_follow')->where(['openid'=>I('openid'),'follow_openid'=> $vo['openid']])->find();
                    $news[$ko]['is_follow'] =$follow?true:false;
                }
                if($news){
                    $news['type'] = 'member';
                    $arr = $news;
                }

            }
            //推荐文章
            if($vv['type'] == "news"){
                $count2 = M('news')->alias("n")->where(['n.type'=>0,'wid'=>session('wid')])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getNews($abs,$vv['count'],$wid,$limit,$count2,$vv['type'],0);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                    $count3 = M('news_reply')
                        ->where(array('nid' => $vo['id']))
                        ->group('openid')
                        ->count('id');
                    if (empty($count3)) {
                        $count3 = 0;
                    }
                    if(!empty($vo['video_url'])){
                        $url = $this->handleVideoUrl($vo['video_url']);
                        $news[$ko]['video_url'] = $url;
                    }
                    $news[$ko]['reply_num'] = $count3;
                    $news[$ko]['add_time'] = $this->getAnnounceTime($vo['create_time']);
                }
                if($news){
                    $news['type'] = 'news';
                    $arr = $news;
                }
            }
            //广告
            if($vv['type'] == 'ad'){
                $count2 = M('news')->alias("n")->where(['n.type'=>1,'wid'=>session('wid')])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getNews($abs,$vv['count'],$wid,$limit,$count2,$vv['type'],1);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }

                if($news){
                    $news['type'] = 'ad';
                    $arr = $news;
                }
            }
            //商品(无需自动填充)
            if($vv['type'] == 'goods'){
                $count2 =M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                $news = M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])
                    ->order("t.sort desc")
                    ->limit("{$limit},{$vv['count']}")->select();
                if(!$news){
                    $news = M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                        ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])
                        ->order("t.sort desc")
                        ->limit("0,{$vv['count']}")->select();
                }
                if($news){
                    $news['type'] = 'goods';
                    $arr = $news;
                }
            }
            //话题
            if($vv['type'] == 'topic'){
                $count2 =M('quan')->alias("q")->field("q.*")
                    ->where(['q.wid'=>session('wid'),["q.pics <> ''"],["q.topic <> ''"]])->group('q.topic')->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                /* $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                             AND wid = {$wid}
                             GROUP BY topic
                             ORDER BY
                             (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                             create_time DESC
                             limit ".$limit.",{$vv['count']}";
                 $news = M()->query($sql);*/
                $news = $this->getTopic($abs,$vv['count'],$wid,$limit,$count2);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }
                if($news){
                    $news['type'] = 'topic';
                    $arr = $news;
                }
            }
            //商家(无需自动填充)
            if($vv['type'] == 'shop'){
                $count2 =M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                $news = M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->limit("{$limit},{$vv['count']}")->order("t.sort desc")->select();

                if(!$news){
                    $news =  M("shop")
                        ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                        ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                        ->limit("0,{$vv['count']}")->order("t.sort desc")->select();
                }
                //商户距离计算
                if (I('la') != 'undefined' && I('lo') != 'undefined') {
                    foreach($news as $ko=>$vo){
                        if ($vo['latitude'] && $vo['longitude']) {
                            $earthRadius = 6367000;
                            $lat1 = (float) I('la');//纬度
                            $lng1 = (float) I('lo');//经度
                            $lat2 = (float) $vo['latitude'];
                            $lng2 = (float) $vo['longitude'];
                            $lat1=($lat1* pi()) / 180;
                            $lng1=($lng1* pi()) / 180;
                            $lat2=($lat2* pi()) / 180;
                            $lng2=($lng2* pi()) / 180;
                            $calcLongitude = $lng2-$lng1;
                            $calcLatitude = $lat2-$lat1;
                            $stepOne = pow(sin($calcLatitude/2),2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude/2),2);
                            $stepTwo = 2* asin(min(1, sqrt($stepOne)));
                            $distance = round($earthRadius*$stepTwo);
                            if ($distance < 1000) {
                                $news[$ko]['r_distance'] = $distance.'米';
                            } else {
                                $distance = $distance / 1000;
                                $news[$ko]['r_distance'] = round($distance, 2).'公里';
                            }
                        } else {
                            $news[$ko]['r_distance'] = '';
                        }
                    }
                } else {
                    $news[]['r_distance'] = '';
                }

                if($news){
                    $news['type'] = 'shop';
                    $arr = $news;
                }
            }
            //圈子
            if($vv['type'] == 'quan'){
                $count2 =M("circle")
                    ->alias("c")->field("c.*")
                    ->where(['c.wid'=>session('wid'),'c.status'=>0])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getCircle($abs,$vv['count'],$wid,$limit,$count2);
                if($news){
                    $news['type'] = 'quan';
                    $arr = $news;
                }
            }
            //问答
            //按顺序返回
            $data[$kk] = $arr;

            unset($limit);
            unset($news);
            unset($arr);
            unset($sql);
            unset($arr2);
        }
        $new['arr'] = $data;
        //去除空值
        foreach($new['arr'] as $k=>$v){
            if(!$v){
                unset($new['arr'][$k]);
            }
        }
        $this->ajaxReturn($new);
    }
    // 首页数据生成方法
    public function index2(){
        $array = [];
        if (isset($_GET['pageNum'])) {
            $page = (int)I('pageNum');
           // $page = ((int)$page) * 10;
        } else {
            $page = 0;
        }

        $map['wid'] = session('wid');
        $new['wechat'] = M('wechat')->where($map)->find();
        $map['is_pay'] = 1;

        //同城头条
        $list = M("InfoOrder")->where($map)->order("is_top desc,top_end_time desc,last_time desc")->limit(0, 10)->select();
        //更新地理位置
        if($_GET['openid']){
            $where['openid'] = $_GET['openid'];
            $member = M('member')->where(['wid'=>session('wid'),'openid'=>$_GET['openid']])->find();
            if(!($member['latitude']>0) && !($member['longitude']>0)){
                $save['latitude'] = I('la');
                $save['longitude'] = I('lo');
                M('member')->where(['wid'=>session('wid'),'openid'=>$_GET['openid']])->save();
            }

        }

        $eq['wid'] = session('wid');
        $eq['status'] = 1;
        $new['list'] = array();

        foreach ($list as $k => $v) {
            $eq['id'] = $v['info_id'];
            switch ($v['action']) {
                case 'job':
                    $vo = M("Job")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'job'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'job';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'house':
                    $vo = M("House")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'house'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'house';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'info':
                    $eq1['tp_info.wid'] = session('wid');
                    $eq1['tp_info.status'] = 1;
                    $eq1['tp_info.id'] = $v['info_id'];
                    $vo = M("Info")->join('tp_member ON tp_info.openid = tp_member.openid')->where($eq1)->field("tp_info.*, tp_member.nickname, tp_member.headimgurl")->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'info'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'info';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'pinche':
                    $vo = M("pinche")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'pinche'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'pinche';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                
                default:
                    # code...
                    break;
            }
        }
        //排序模板
        $arr = [];
        //查出对应模板的信息
        $wid = session('wid');
        $tuilist = M('tui_cate')->where(['status'=>1,'wid'=>session('wid')])->order('sort desc')->select();
        foreach($tuilist as $kk=>$vv){
            //查出有几条
            $count = M("tui")->where(['wid'=>$vv['wid'],'type'=>$vv['type'],'status'=>1])->count();
            $sum = M('tui_cate')->where(['wid'=>$vv['wid'],'type'=>$vv['type'],'status'=>1])->sum('count');
            //初始化分页变量
            if(session($vv['type'].'count')){
                //没有page时候 session($vv['type']) +上次的count
                $limit = session($vv['type']) + session($vv['type'].'count');
            }else{
                //有page时候 (page-1)*sum
                $limit  = ($page-1) * $sum ;
                session($vv['type'],$limit);
                session($vv['type'].'count',$vv['count']);
            }
            //用户
            if($vv['type'] == "member"){
                $count2 = M('member')->alias("m")->where(['m.wid'=>session('wid')])->count();
                $sql ="SELECT count(*) AS c, q.openid,m.mid,m.nickname,m.headimgurl,m.user_monologue
                        FROM
                            tp_quan q
                        LEFT JOIN tp_member m ON m.openid = q.openid
                        WHERE q.wid = {$wid} AND m.nickname is not NULL
                        GROUP BY openid
                        ORDER BY
                        (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = q.wid AND type = '{$vv['type']}' and aid = m.mid )DESC, c DESC
                        LIMIT ".$limit.",{$vv['count']}";
                $news = M()->query($sql);
                foreach($news as $ko=>$vo){
                    //是否关注
                    $follow = M('quan_follow')->where(['openid'=>I('openid'),'follow_openid'=> $vo['openid']])->find();
                    $news[$ko]['is_follow'] =$follow?true:false;
                }
                if($news){
                    $news['type'] = 'member';
                    $arr = $news;
                }

            }
            //推荐文章
            if($vv['type'] == "news"){
                $count2 = M('news')->alias("n")->where(['n.type'=>0,'wid'=>session('wid')])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getNews($abs,$vv['count'],$wid,$limit,$count2,$vv['type'],0);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                    $count3 = M('news_reply')
                        ->where(array('nid' => $vo['id']))
                        ->group('openid')
                        ->count('id');
                    if (empty($count3)) {
                        $count3 = 0;
                    }
                    if(!empty($vo['video_url'])){
                        $url = $this->handleVideoUrl($vo['video_url']);
                        $news[$ko]['video_url'] = $url;
                    }
                    $news[$ko]['reply_num'] = $count3;
                    $news[$ko]['add_time'] = $this->getAnnounceTime($vo['create_time']);
                }
                if($news){
                    $news['type'] = 'news';
                    $arr = $news;
                }
            }
            //广告
            if($vv['type'] == 'ad'){
                $count2 = M('news')->alias("n")->where(['n.type'=>1,'wid'=>session('wid')])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getNews($abs,$vv['count'],$wid,$limit,$count2,$vv['type'],1);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }

                if($news){
                    $news['type'] = 'ad';
                    $arr = $news;
                }
            }
            //商品(无需自动填充)
            if($vv['type'] == 'goods'){
                $count2 =M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                $news = M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])
                    ->order("t.sort desc")
                    ->limit("{$limit},{$vv['count']}")->select();
                if(!$news){
                    $news = M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                        ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])
                        ->order("t.sort desc")
                        ->limit("0,{$vv['count']}")->select();
                }
                if($news){
                    $news['type'] = 'goods';
                    $arr = $news;
                }
            }
            //话题
            if($vv['type'] == 'topic'){
                $count2 =M('quan')->alias("q")->field("q.*")
                    ->where(['q.wid'=>session('wid'),["q.pics <> ''"],["q.topic <> ''"]])->group('q.topic')->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
               /* $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                            limit ".$limit.",{$vv['count']}";
                $news = M()->query($sql);*/
                $news = $this->getTopic($abs,$vv['count'],$wid,$limit,$count2);
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }
                if($news){
                    $news['type'] = 'topic';
                    $arr = $news;
                }
            }
            //商家(无需自动填充)
            if($vv['type'] == 'shop'){
                $count2 =M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                $news = M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->limit("{$limit},{$vv['count']}")->order("t.sort desc")->select();

                if(!$news){
                    $news =  M("shop")
                        ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                        ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                        ->limit("0,{$vv['count']}")->order("t.sort desc")->select();
                }
                //商户距离计算
                if (I('la') != 'undefined' && I('lo') != 'undefined') {
                    foreach($news as $ko=>$vo){
                        if ($vo['latitude'] && $vo['longitude']) {
                            $earthRadius = 6367000;
                            $lat1 = (float) I('la');//纬度
                            $lng1 = (float) I('lo');//经度
                            $lat2 = (float) $vo['latitude'];
                            $lng2 = (float) $vo['longitude'];
                            $lat1=($lat1* pi()) / 180;
                            $lng1=($lng1* pi()) / 180;
                            $lat2=($lat2* pi()) / 180;
                            $lng2=($lng2* pi()) / 180;
                            $calcLongitude = $lng2-$lng1;
                            $calcLatitude = $lat2-$lat1;
                            $stepOne = pow(sin($calcLatitude/2),2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude/2),2);
                            $stepTwo = 2* asin(min(1, sqrt($stepOne)));
                            $distance = round($earthRadius*$stepTwo);
                            if ($distance < 1000) {
                                $news[$ko]['r_distance'] = $distance.'米';
                            } else {
                                $distance = $distance / 1000;
                                $news[$ko]['r_distance'] = round($distance, 2).'公里';
                            }
                        } else {
                            $news[$ko]['r_distance'] = '';
                        }
                    }
                } else {
                    $news[]['r_distance'] = '';
                }

                if($news){
                    $news['type'] = 'shop';
                    $arr = $news;
                }
            }
            //圈子
            if($vv['type'] == 'quan'){
                $count2 =M("circle")
                    ->alias("c")->field("c.*")
                    ->where(['c.wid'=>session('wid'),'c.status'=>0])->count();
                $limit = ($limit) >$count2? ($limit % $count2):$limit ;
                $limit =($limit < 0)?0:$limit;
                //判断当前条数，循环用
                $abs =abs($count2 - $limit);
                $news = $this->getCircle($abs,$vv['count'],$wid,$limit,$count2);
                if($news){
                    $news['type'] = 'quan';
                    $arr = $news;
                }
            }
            //问答
            //按顺序返回
            $data[$kk] = $arr;

            unset($limit);
            unset($news);
            unset($arr);
            unset($sql);
            unset($arr2);
        }
        $new['arr'] = $data;
        //去除空值
        foreach($new['arr'] as $k=>$v){
            if(!$v){
                unset($new['arr'][$k]);
            }
        }
        $this->ajaxReturn($new);
    }

    public function getCircle($abs,$count,$wid,$limit,$count2){
        if($abs >=$count){
            $sql = "SELECT * FROM tp_circle WHERE wid ={$wid}
                            ORDER BY
                            ( SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'quan' and aid = tp_circle.id )desc,
                            ( SELECT count(*)  FROM tp_circle_member WHERE uid = tp_circle.id AND wid ={$wid}) desc
                            limit ".$limit.",{$count}";
            $news = M()->query($sql);
            //echo M()->getLastSql();
        }else{
            //limit/count2 == 1 从头开始
            if($limit/$count2 == 1){
                $sql = "SELECT * FROM tp_circle WHERE wid ={$wid}
                            ORDER BY
                            ( SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'quan' and aid = tp_circle.id )desc,
                            ( SELECT count(*)  FROM tp_circle_member WHERE uid = tp_circle.id AND wid ={$wid}) desc
                        LIMIT 0,{$count}";
                $news = M()->query($sql);
            }
            //limit/count2 < 1 补齐
            if($limit/$count2 < 1){
                //补齐
                $sql = "SELECT * FROM tp_circle WHERE wid ={$wid}
                            ORDER BY
                            ( SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'quan' and aid = tp_circle.id )desc,
                            ( SELECT count(*)  FROM tp_circle_member WHERE uid = tp_circle.id AND wid ={$wid}) desc
                        LIMIT ".(($limit-1)>0?($limit-1):0).",{$count}";
                $news = M()->query($sql);
                $pagesize =$count - count($news);
                if($pagesize > 0){
                    //补齐
                    $sql2 = "SELECT * FROM tp_circle WHERE wid ={$wid}
                            ORDER BY
                            ( SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'quan' and aid = tp_circle.id )desc,
                            ( SELECT count(*)  FROM tp_circle_member WHERE uid = tp_circle.id AND wid ={$wid}) desc
                        LIMIT 0,{$pagesize}";
                    $list = M()->query($sql2);
                    array_merge($news,$list);
                }
            }
            //limit/count2 >1  取余
            if($limit/$count2 > 1){
                $sql = "SELECT * FROM tp_circle WHERE wid ={$wid}
                            ORDER BY
                            ( SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'quan' and aid = tp_circle.id )desc,
                            ( SELECT count(*)  FROM tp_circle_member WHERE uid = tp_circle.id AND wid ={$wid}) desc
                        LIMIT {$limit},{$count}";
                $news = M()->query($sql);
            }
        }
        return $news;
    }
    public function getTopic($abs,$count,$wid,$limit,$count2){
        if($abs >=$count){
            $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                            limit ".$limit.",{$count}";
            $news = M()->query($sql);
            //echo M()->getLastSql();
        }else{
            //limit/count2 == 1 从头开始
            if($limit/$count2 == 1){
                $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                        LIMIT 0,{$count}";
                $news = M()->query($sql);
            }
            //limit/count2 < 1 补齐
            if($limit/$count2 < 1){
                //补齐
                $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                        LIMIT ".(($limit-1)>0?($limit-1):0).",{$count}";
                $news = M()->query($sql);
                $pagesize =$count - count($news);
                if($pagesize > 0){
                    //补齐
                    $sql2 = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                        LIMIT 0,{$pagesize}";
                    $list = M()->query($sql2);
                    array_merge($news,$list);
                }
            }
            //limit/count2 >1  取余
            if($limit/$count2 > 1){
                $sql = "SELECT  * FROM tp_quan WHERE type = 0 AND pics <> '' AND topic <> ''
                            AND wid = {$wid}
                            GROUP BY topic
                            ORDER BY
                            (SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = {$wid} AND type = 'topic' and content =tp_quan.topic ) desc,
                            create_time DESC
                        LIMIT {$limit},{$count}";
                $news = M()->query($sql);
            }
        }
        return $news;
    }


    public function getNews($abs,$count,$wid,$limit,$count2,$type,$type2){
        if($abs >=$count){
            $sql = "SELECT n.* FROM tp_news n
                        LEFT JOIN tp_tui t ON t.aid = n.id
                        WHERE
                            n.type = {$type2}
                        AND n.wid = {$wid}
                        GROUP BY
                            n.id
                        ORDER BY
                            (  SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = n.wid AND type = '{$type}' AND aid = n.id ) DESC,
                            n.create_time DESC
                        LIMIT {$limit},{$count}";
            $news = M()->query($sql);
        }else{
            //limit/count2 == 1 从头开始
            if($limit/$count2 == 1){
                $sql = "SELECT n.* FROM tp_news n
                        LEFT JOIN tp_tui t ON t.aid = n.id
                        WHERE
                            n.type = {$type2}
                        AND n.wid = {$wid}
                        GROUP BY
                            n.id
                        ORDER BY
                            (  SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = n.wid AND type = '{$type}' AND aid = n.id ) DESC,
                            n.create_time DESC
                        LIMIT 0,{$count}";
                $news = M()->query($sql);
            }
            //limit/count2 < 1 补齐
            if($limit/$count2 < 1){
                //补齐
                $sql = "SELECT n.* FROM tp_news n
                        LEFT JOIN tp_tui t ON t.aid = n.id
                        WHERE
                            n.type = {$type2}
                        AND n.wid = {$wid}
                        GROUP BY
                            n.id
                        ORDER BY
                            (  SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = n.wid AND type = '{$type}' AND aid = n.id ) DESC,
                            n.create_time DESC
                        LIMIT ".(($limit-1)>0?($limit-1):0).",{$count}";
                $news = M()->query($sql);
                $pagesize =$count - count($news);
                if($pagesize > 0){
                    //补齐
                    $sql2 = "SELECT n.* FROM tp_news n
                        LEFT JOIN tp_tui t ON t.aid = n.id
                        WHERE
                            n.type = {$type2}
                        AND n.wid = {$wid}
                        GROUP BY
                            n.id
                        ORDER BY
                            (  SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = n.wid AND type = '{$type}' AND aid = n.id ) DESC,
                            n.create_time DESC
                        LIMIT 0,{$pagesize}";
                    $list = M()->query($sql2);
                    array_merge($news,$list);
                }
            }
            //limit/count2 >1  取余
            if($limit/$count2 > 1){
                $sql = "SELECT n.* FROM tp_news n
                        LEFT JOIN tp_tui t ON t.aid = n.id
                        WHERE
                            n.type = {$type2}
                        GROUP BY
                            n.id
                        ORDER BY
                            (  SELECT sort FROM tp_tui WHERE STATUS = 1 AND wid = n.wid AND type = '{$type}' AND aid = n.id ) DESC,
                            n.create_time DESC
                        AND n.wid = {$wid}
                        LIMIT {$limit},{$count}";
                $news = M()->query($sql);
            }
        }
        return $news;
    }

    /*
     * 获取自动填充内容
     * @param  string $type 内容类型
     * @param  int $limit 查询数量
     * @param  int $page 起始位置
     * @param  string $openid 查询用户是否关注
     * @param  int $id id
     * @return array $list
     */
    protected function getInfo($type,$limit,$page = 0,$openid='')
    {
        //按同城圈发帖量查询用户
        if($type == "member"){
            $sql = "SELECT count(*) as c,q.openid,m.nickname,m.headimgurl,m.user_monologue from tp_quan q left join
                    tp_member m on m.openid =q.openid
                    where q.wid = ". session('wid') ."
                    and mid not in( SELECT aid from tp_tui where status =1 and wid =  ".session('wid')."  and type ='member')
                     GROUP BY openid ORDER BY c  desc
                    limit ".$page.",".$limit;
            $news = M()->query($sql);
            //是否关注
            foreach($news as $k=>$v){
                $follow = M('quan_follow')->where(['openid'=>$openid,'follow_openid'=> $v['openid']])->find();
                $news[$k]['is_follow'] =$follow?true:false;
            }
        }
        //咨询:最新发布的咨询
        if($type == "news"){
            $sql = "select * from tp_news  WHERE type=0 and wid=".session('wid')."
                    and id not in (SELECT aid from tp_tui where status =1 and wid =  ".session('wid')."  and type ='news')
                    order by create_time DESC limit {$page},{$limit}";
            $news = M()->query($sql);
            //$news = M('news')->where(['type'=>0,['wid'=>session('wid')]])->order("create_time DESC")->limit($page,$limit)->select();
            foreach($news as $kk =>$vv){
                if(strpos($vv['pics'],",")) {
                    $pics = explode(',', $vv['pics']);
                    $arr2[] = $pics[0];
                    $news[$kk]['pics'] = $arr2;
                }else{
                    $arr2[] = $vv['pics'];
                    $news[$kk]['pics'] =$arr2;
                }
                unset($arr2);
                $count = M('news_reply')
                    ->where(array('nid'=>$vv['id']))
                    ->group('openid')
                    ->count('id');
                if(empty($count)){
                    $count = 0;
                }
                if(!empty($vv['video_url'])){
                    $url = $this->handleVideoUrl($vv['video_url']);
                    $news[$kk]['video_url'] = $url;
                }
                $news[$kk]['reply_num'] = $count;
                $news[$kk]['add_time'] = $this->getAnnounceTime($vv['create_time']);
            }
        }
        //广告
        if($type == 'ad'){
            $sql = "select * from tp_news  WHERE type=1 and wid=".session('wid')."
                    and id not in (SELECT aid from tp_tui where status =1 and wid =  ".session('wid')."  and type ='ad')
                    order by create_time DESC limit {$page},{$limit}";
            $news = M()->query($sql);
            foreach($news as $kk =>$vv){
                if(strpos($vv['pics'],",")) {
                    $pics = explode(',', $vv['pics']);
                    $arr2[] = $pics[0];
                    $news[$kk]['pics'] = $arr2;
                }else{
                    $arr2[] = $vv['pics'];
                    $news[$kk]['pics'] =$arr2;
                }
                unset($arr2);
            }
        }
        //话题
        if($type == 'topic'){
            $sql = "select * from tp_quan  WHERE type=0  and pics <> '' and topic <> '' and wid=".session('wid')."
                    and topic not in (SELECT content from tp_tui where status =1 and wid =  ".session('wid')."  and type ='topic')
                    order by create_time DESC limit {$page},{$limit}";
            $news = M()->query($sql);
            foreach ($news as $key => $value) {
                if(strpos($value['pics'],",")) {
                    $pics = explode(',', $value['pics']);
                    $arr2[] = $pics[0];
                    $news[$key]['pics'] = $arr2;
                }else{
                    $arr2[] = $value['pics'];
                    $news[$key]['pics'] =$arr2;
                }
                unset($arr2);
            }
        }
        //圈子(用户量或者最新发帖的圈子)
        if($type == 'quan'){
            $sql = "select * from tp_circle
                    where id not in( SELECT aid from tp_tui where status =1 and wid =  ".session('wid')."  and type ='quan')
                    ORDER BY
                    (select count(*) from tp_circle_member where uid = tp_circle.id and wid=\".session('wid').\") desc
                    limit {$page},{$limit}";
            $news = M()->query($sql);
        }
        return $news;
    }
//我的发布
    public function My_message(){
        $array = [];
        if (isset($_GET['pageNum'])) {
            $page = I('pageNum');
            // $page = ((int)$page + 1) * 10;
        } else {
            $page = 0;
        }

        $map['wid'] = session('wid');
        $new['wechat'] = M('wechat')->where($map)->find();
        $map['is_pay'] = 1;

        if($_GET['openid']){
            $map['openid'] = $_GET['openid'];
        }
        //同城头条
        $list = M("InfoOrder")->where($map)->order("is_top desc,top_end_time desc,last_time desc")->limit(0, 10)->select();
        $eq['wid'] = session('wid');
        $eq['status'] = 1;
        $new['list'] = array();

        foreach ($list as $k => $v) {
            $eq['id'] = $v['info_id'];
            switch ($v['action']) {
                case 'job':
                    $vo = M("Job")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'job'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'job';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'house':
                    $vo = M("House")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'house'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'house';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'info':
                    $eq1['tp_info.wid'] = session('wid');
                    $eq1['tp_info.status'] = 1;
                    $eq1['tp_info.id'] = $v['info_id'];
                    $vo = M("Info")->join('tp_member ON tp_info.openid = tp_member.openid')->where($eq1)->field("tp_info.*, tp_member.nickname, tp_member.headimgurl")->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'info'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'info';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;
                case 'pinche':
                    $vo = M("pinche")->where($eq)->order("last_time desc")->find();
                    $cid = M('InfoOrder')->where(array('info_id'=>$vo['id'],'action'=>'pinche'))->getField('sub_cid');
                    $vo['sub_cid'] = $cid;
                    if(!$vo){
                        break;
                    }
                    if($vo['is_top'] == 1 && $vo['top_end_time'] < date("Y-m-d H:i:s")){
                        $vo['is_top'] = 0;
                    }
                    $vo['action'] = 'pinche';
                    $vo['tags'] = explode(',', $vo['tag']);
                    $new['list'][] = $vo;
                    break;

                default:
                    # code...
                    break;
            }
        }
        //排序模板
        $arr = [];
        //查出对应模板的信息
        $tuilist = M('tui_cate')->where(['status'=>1,'wid'=>session('wid')])->order('sort desc')->select();
        foreach($tuilist as $kk=>$vv){
            $array[$vv['type']] = $array[$vv['type']]?$array[$vv['type']]:$page;
            //查出有几条
            $count = M("tui")->where(['wid'=>$vv['wid'],'type'=>$vv['type'],'status'=>1])->count();
            //用户
            if($vv['type'] == "member"){
                $count2 = M('member')->alias("m")->where(['m.wid'=>session('wid')])->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;
                $news = M('member')->alias("m")->field("m.*")->join("tp_tui t on t.aid = m.mid")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1])->order("t.sort desc")->limit("{$array[$vv['type']]},{$vv['count']}")->select();
                foreach($news as $ko=>$vo){
                    //是否关注
                    $follow = M('quan_follow')->where(['openid'=>I('openid'),'follow_openid'=> $vo['openid']])->find();
                    $news[$ko]['is_follow'] =$follow?true:false;
                }
                if($count < $vv['count']){
                    //需要填充数据
                    $list = $this->getInfo('member',($vv['count']-count($news)),$array[$vv['type']],I('openid'));
                    $news = array_merge($news,$list);
                }
                if($news){
                    $news['type'] = 'member';
                    $arr = $news;
                }

            }
            //推荐文章
            if($vv['type'] == "news"){
                $count2 = M('news')->alias("n")->where(['n.type'=>0,'wid'=>session('wid')])->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =($array[$vv['type']] < 0)?0:$array[$vv['type']] ;
                $news = M('news')->alias("n")->field("n.*")->join("tp_tui t on t.aid = n.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'n.type'=>0])->order("t.sort desc")
                    ->limit("{$array[$vv['type']]},{$vv['count']}")->select();
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                    $count3 = M('news_reply')
                        ->where(array('nid' => $vo['id']))
                        ->group('openid')
                        ->count('id');
                    if (empty($count3)) {
                        $count3 = 0;
                    }
                    $news[$ko]['reply_num'] = $count3;
                    $news[$ko]['add_time'] = $this->getAnnounceTime($vo['create_time']);
                }
                if($count < $vv['count']){
                    //需要填充数据
                    $list = $this->getInfo('news',($vv['count']-count($news)),$array[$vv['type']]);
                    $news = array_merge($news,$list);
                }
                if($news){
                    $news['type'] = 'news';
                    $arr = $news;
                }
            }
            //广告
            if($vv['type'] == 'ad'){
                $count2 =M('news')->alias("n")
                    ->where(['n.wid'=>session('wid'),'n.type'=>1])->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;
                $news = M('news')->alias("n")->field("n.*")->join("tp_tui t on t.aid = n.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'n.type'=>1])->order("t.sort desc")->limit("{$array[$vv['type']]},{$vv['count']}")->select();

                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }
                if($count < $vv['count']){
                    //需要填充数据
                    $list = $this->getInfo('ad',($vv['count']-count($news)),$array[$vv['type']]);
                    $news = array_merge($news,$list);
                }
                if($news){
                    $news['type'] = 'ad';
                    $arr = $news;
                }
            }
            //商品(无需自动填充)
            if($vv['type'] == 'goods'){
                $count2 =M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;

                $news = M('goods')->alias("g")->field("g.*")->join("tp_tui t on t.aid = g.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'g.status'=>1])->order("t.sort desc")->limit("{$array[$vv['type']]},{$vv['count']}")->select();
                if($news){
                    $news['type'] = 'goods';
                    $arr = $news;
                }
            }
            //话题
            if($vv['type'] == 'topic'){
                $count2 =M('quan')->alias("q")->field("q.*")
                    ->where(['q.wid'=>session('wid'),["q.pics <> ''"],["q.topic <> ''"]])->group('q.topic')->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;
                $news = M('quan')->alias("q")->field("q.*")->join("tp_tui t on t.content = q.topic")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,["q.pics <> ''"],["q.topic <> ''"]])->limit("{$array[$vv['type']]},{$vv['count']}")->group('q.topic')->order("t.sort desc")->select();
                foreach($news as $ko=>$vo) {
                    if(strpos($vo['pics'],",")) {
                        $pics = explode(',', $vo['pics']);
                        $arr2[] = $pics[0];
                        $news[$ko]['pics'] = $arr2;
                    }else{
                        $arr2[] = $vo['pics'];
                        $news[$ko]['pics'] =$arr2;
                    }
                    unset($arr2);
                }
                if($count < $vv['count']){
                    //需要填充数据
                    $list = $this->getInfo('topic',($vv['count']-count($news)),$array[$vv['type']]);
                    $news = array_merge($news,$list);
                }
                if($news){
                    $news['type'] = 'topic';
                    $arr = $news;
                }
            }
            //商家(无需自动填充)
            if($vv['type'] == 'shop'){
                $count2 =M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;

                $news = M("shop")
                    ->alias("s")->field("s.*")->join("tp_tui t on t.aid = s.shop_id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,['join_end_time' => ['gt', date('Y-m-d H:i:s', time())]]])
                    ->limit("{$array[$vv['type']]},{$vv['count']}")->order("t.sort desc")->select();
                //商户距离计算
                if (I('la') != 'undefined' && I('lo') != 'undefined') {
                    foreach($news as $ko=>$vo){
                        if ($vo['latitude'] && $vo['longitude']) {
                            $earthRadius = 6367000;
                            $lat1 = (float) I('la');//纬度
                            $lng1 = (float) I('lo');//经度
                            $lat2 = (float) $vo['latitude'];
                            $lng2 = (float) $vo['longitude'];
                            $lat1=($lat1* pi()) / 180;
                            $lng1=($lng1* pi()) / 180;
                            $lat2=($lat2* pi()) / 180;
                            $lng2=($lng2* pi()) / 180;
                            $calcLongitude = $lng2-$lng1;
                            $calcLatitude = $lat2-$lat1;
                            $stepOne = pow(sin($calcLatitude/2),2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude/2),2);
                            $stepTwo = 2* asin(min(1, sqrt($stepOne)));
                            $distance = round($earthRadius*$stepTwo);
                            if ($distance < 1000) {
                                $news[$ko]['r_distance'] = $distance.'米';
                            } else {
                                $distance = $distance / 1000;
                                $news[$ko]['r_distance'] = round($distance, 2).'公里';
                            }
                        } else {
                            $news[$ko]['r_distance'] = '';
                        }
                    }
                } else {
                    $news[]['r_distance'] = '';
                }

                if($news){
                    $news['type'] = 'shop';
                    $arr = $news;
                }
            }
            //圈子
            if($vv['type'] == 'quan'){

                $count2 =M("circle")
                    ->alias("c")->field("c.*")
                    ->where(['c.wid'=>session('wid'),'c.status'=>0])->count();
                $array[$vv['type']] = $array[$vv['type']] >$count2? ($array[$vv['type']] % $count2 ) -1:$array[$vv['type']] ;
                $array[$vv['type']] =$array[$vv['type']] <0?0:$array[$vv['type']] ;
                $news = M("circle")
                    ->alias("c")->field("c.*")->join("tp_tui t on t.aid = c.id")
                    ->where(['t.type'=>$vv['type'],'t.wid'=>session('wid'),'t.status'=>1,'c.status'=>0])
                    ->limit("{$array[$vv['type']]},{$vv['count']}")->order("t.sort desc")->select();
                if($count < $vv['count']){
                    //需要填充数据
                    $list = $this->getInfo('quan',($vv['count']-count($news)),$array[$vv['type']]);
                    $news = array_merge($news,$list);
                }
                if($news){
                    $news['type'] = 'quan';
                    $arr = $news;
                }
            }
            //问答
            //按顺序返回
            $data[$kk] = $arr;
            $array[$vv['type']] = $array[$vv['type']]?($array[$vv['type']] + $vv['count']):($page + $vv['count']);
            unset($news);
            unset($arr);
            unset($arr2);
        }
        $new['arr'] = $data;
        //去除空值
        foreach($new['arr'] as $k=>$v){
            if(!$v){
                unset($new['arr'][$k]);
            }
        }
        $this->ajaxReturn($new);
    }


    public function mine(){
        $map['openid'] = $_POST['openid'];
        $map['wid'] = session('wid');
        $map['is_pay'] = 1;
        $where['wid'] = session('wid');
        $where['openid'] = I('openid');
        //发布
        $info['info_num'] = M("InfoOrder")->where($map)->count();
        //余额，商家加余额
        $shop = M("Shop")->where($map)->find();
        if ($shop) {
            $info['balance_money'] = $shop['money'];
        }else{
            $info['balance_money'] = 0;
        }
        //是否有圈子
        $r = M('circle')->where(['wid'=>session('wid'),'openid'=>$_POST['openid']])->find();
        $info['circle'] = $r?1:0;
        //优惠券数量
        $info['coupon_num'] = M("CouponLog")->where($where)->order("create_time desc")->count();
        //关注
        $ShopFollow = M('ShopFollow') ->where(array('openid'=>$_POST['openid']))->count();
        $info['ShopFollow'] = $ShopFollow;
        //店铺信息是否完善
        if($shop && $shop['status'] == 1 ){
            if(!$shop['logo_url'] ||!$shop['cate']){
                $info['jump'] = 1;
            }
        }else{
            $info['jump'] = 0;
        }


        $this->ajaxReturn($info);

    }

    public function getCitySelect(){
        $map['wid'] = session('wid');
        $wechat = M("Wechat")->where($map)->find();

        $where['city_code'] = $wechat['city'];
        $city = M("City")->where($where)->find();
        $where1['pid'] = $city['id'];

        $site_arr = array(
            'title'=>'全部地区',
            'is_show'=>false,
            'list'=>array(

            )
        );

        $site_arr2 = M("City")->where($where1)->getField("city_name",true);
        if($wechat['city'] == 0){
            $site1 = "全国";
        }else{
            $site1  = $city["city_name"];
            if(!$site_arr2){
                $site_arr2 = array("全辖区");
            }
        }

        foreach ($site_arr2 as $key => $value) {
            $site_arr2[$key] = array(
                'value'=> $value,
                'is_selected'=>false
            );
        }
        $site_arr = array(
            'title'=>'全部地区',
            'is_show'=>false,
            'list'=>array(
                'value'=> $site1,
                'is_selected'=>false
            )
        );
        if($site_arr2){
            $site_arr['list']['sub_list'] = $site_arr2;
        }
        $this->ajaxReturn($site_arr);
    }

    public function getAddInfo(){
        $map['wid'] = session('wid');
        $wechat = M("Wechat")->where($map)->find();

        $map['id'] = $_GET['id'];
        $info = M("Cate")->where($map)->find();
        $form = array();
        $tags = array();
        $res = array();
        if(!empty($info['tags'])){
            $info['tags'] = explode(',', $info['tags']);
            foreach ($info['tags'] as $key => $value) {
                $tags[] = array('title'=>$value, 'selected'=>false);
            }
        }else{
            $tags = array();
        }
        $tags_input = array('type'=>'tag', 'title'=>'标签选择', 'name'=>'tag', 'tags'=>$tags, 'is_show_tags_input'=>false, 'tags_input_value'=>'');
        
        $top_input = array('type'=>'top');

        $where['city_code'] = $wechat['city'];
        $city = M("City")->where($where)->find();
        $where1['pid'] = $city['id'];
        $site_arr2 = M("City")->where($where1)->getField("city_name",true);
        if($wechat['city'] == 0){
            $site_arr1 = array("全国");
        }else{
            $site_arr1 = array($city["city_name"]);
            if(!$site_arr2){
                $site_arr2 = array("全辖区");
            }
        }
        $site_input = array('type'=>'picker2', 'title'=>'区域', 'name'=>array('county_name', 'site_name') 
                ,'range'=>array($site_arr1, $site_arr2)
                , 'value'=>array(0,0));
        // $form[] = array('type'=>'pic', 'title'=>'房源图片', 'name'=>'pics', 'num'=>1);

        // print_r($info);
        $res['info'] = $info;
        if($info['sub_type'] == 'quanzhi'){
            $res['add_url'] = "https://www.58zltc.com/api.php/Job/add?type=1";
            //$res['add_url'] = "https://www.58zltc.com/api.php/Job/add?type=1";
            $res['index_url'] = "/pages/index/job/index";

            if(!empty($_GET['infoid'])){
                $jobInfo = M('job')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'职位名称', 'name'=>'title','value'=>$jobInfo['title']);
            $pay_money_range = array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上');
            foreach($pay_money_range as $pk=>$pv){
                if($pv == $jobInfo['pay_money']){
                    $pay_money = $pk;
                }
            }
            if(empty($pay_money)){
                $pay_money = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'薪资水平', 'name'=>'pay_money'
                ,'range'=>array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上')
                , 'value'=>$pay_money);

            $form[] = $site_input;
            $job_year_range = array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上');
            foreach($job_year_range as $jk=>$jv){
                if($jv == $jobInfo['job_year']){
                    $job_year = $jk;
                }
            }
            if(empty($job_year)){
                $job_year = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'工作年限', 'name'=>'job_year' 
                ,'range'=>array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上')
                , 'value'=>$job_year);
            $education_range = array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士');
            foreach($education_range as $ek=>$ev){
                if($ev == $jobInfo['education']){
                    $education = $ek;
                }
            }
            if(empty($education)){
                $education = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'学历要求', 'name'=>'education' 
                ,'range'=>array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士')
                , 'value'=>$education);
            $form[] = array('type'=>'number', 'title'=>'招聘人数', 'name'=>'num','value'=>$jobInfo['num']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'公司名称', 'name'=>'company_name','value'=>$jobInfo['company_name']);
            $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site','value'=>$jobInfo['company_site']);
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$jobInfo['tel']);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$jobInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'职位详情', 'name'=>'content','value'=>$jobInfo['content']);
        }elseif($info['sub_type'] == 'qiu'){
            $res['add_url'] = "https://www.58zltc.com/api.php/Job/add?type=2";
            //$res['add_url'] = "https://www.58zltc.com/api.php/Job/add?type=2";
            $res['index_url'] = "/pages/index/job/index";

            if(!empty($_GET['infoid'])){
                $jobInfo = M('job')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'姓名', 'name'=>'username','value'=>$jobInfo['username']);
            $form[] = array('type'=>'text', 'title'=>'意向岗位', 'name'=>'title','value'=>$jobInfo['title']);
            $pay_money_range = array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上');
            foreach($pay_money_range as $pk=>$pv){
                if($pv == $jobInfo['pay_money']){
                    $pay_money = $pk;
                }
            }
            if(empty($pay_money)){
                $pay_money = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'意向薪资', 'name'=>'pay_money'
                ,'range'=>array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上')
                , 'value'=>$pay_money);
            $form[] = $site_input;
            $job_year_range = array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上');
            foreach($job_year_range as $jk=>$jv){
                if($jv == $jobInfo['job_year']){
                    $job_year = $jk;
                }
            }
            if(empty($job_year)){
                $job_year = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'工作经验', 'name'=>'job_year' 
                ,'range'=>array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上')
                , 'value'=>$job_year);
            $education_range = array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士');
            foreach($education_range as $ek=>$ev){
                if($ev == $jobInfo['education']){
                    $education = $ek;
                }
            }
            if(empty($education)){
                $education = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'学历', 'name'=>'education' 
                ,'range'=>array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士')
                , 'value'=>$education);
            $sex_range = array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士');
            foreach($sex_range as $sk=>$sv){
                if($sv == $jobInfo['sex']){
                    $sex = $sk;
                }
            }
            if(empty($sex)){
                $sex = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'性别', 'name'=>'sex' 
                ,'range'=>array('男', '女')
                , 'value'=>$sex);
            $form[] = array('type'=>'number', 'title'=>'年龄', 'name'=>'age','value'=>$jobInfo['age']);
            $qiu_type_range = array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士');
            foreach($qiu_type_range as $qk=>$qv){
                if($qv == $jobInfo['qiu_type']){
                    $qiu_type = $qk;
                }
            }
            if(empty($qiu_type)){
                $qiu_type = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'求职类型', 'name'=>'qiu_type'
                ,'range'=>array('全职', '兼职')
                , 'value'=>$qiu_type);
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$jobInfo['tel']);
//            $form[] = array('type'=>'text', 'title'=>'电子邮箱', 'name'=>'email','value'=>$jobInfo['email']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'个人简介', 'name'=>'content','value'=>$jobInfo['content']);
            $form[] = array('type'=>'top');
            $pics = explode(',',$jobInfo['pics']);
            $form[] = array('type'=>'pic', 'title'=>'简历头像', 'name'=>'headimg', 'num'=>1, 'pics'=>$pics);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$jobInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $form[] = $tags_input;
        }elseif($info['sub_type'] == 'jianzhi'){
            $res['add_url'] = "https://www.58zltc.com/api.php/Job/add?type=3";
            $res['index_url'] = "/pages/index/job/index";

            if(!empty($_GET['infoid'])){
                $jobInfo = M('job')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'职位名称', 'name'=>'title');
            $pay_money_range = array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上');
            foreach($pay_money_range as $pk=>$pv){
                if($pv == $jobInfo['pay_money']){
                    $pay_money = $pk;
                }
            }
            if(empty($pay_money)){
                $pay_money = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'薪资水平', 'name'=>'pay_money' 
                ,'range'=>array('面议', '1000元以下', '1000-2000元', '2000-3000元', '3000-5000元', '5000-8000元', '8000-12000元', '12000-20000元', '20000-25000元', '25000元以上')
                , 'value'=>$pay_money);
            $form[] = $site_input;
            $job_year_range = array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上');
            foreach($job_year_range as $jk=>$jv){
                if($jv == $jobInfo['job_year']){
                    $job_year = $jk;
                }
            }
            if(empty($job_year)){
                $job_year = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'工作年限', 'name'=>'job_year' 
                ,'range'=>array('不限', '1年以下', '1-2年', '3-5年', '6-7年', '8-10年', '10年以上')
                , 'value'=>$job_year);
            $education_range = array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士');
            foreach($education_range as $ek=>$ev){
                if($ev == $jobInfo['education']){
                    $education = $ek;
                }
            }
            if(empty($education)){
                $education = 0;
            }
            $form[] = array('type'=>'picker1', 'title'=>'学历要求', 'name'=>'education' 
                ,'range'=>array('不限', '小学', '初中', '高中', '大专', '本科', '硕士', '博士')
                , 'value'=>$education);
            $form[] = array('type'=>'number', 'title'=>'招聘人数', 'name'=>'num','value'=>$jobInfo['num']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'公司名称', 'name'=>'company_name','value'=>$jobInfo['company_name']);
            $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site','value'=>$jobInfo['company_site']);
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$jobInfo['tel']);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$jobInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'职位详情', 'name'=>'content','value'=>$jobInfo['content']);
        }elseif($info['sub_type'] == 'new'){
            $res['add_url'] = "https://www.58zltc.com/api.php/House/add?type=1";
            $res['index_url'] = "/pages/index/house/index";

            if(!empty($_GET['infoid'])){
                $houseInfo = M('house')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'楼盘名称', 'name'=>'title','value'=>$houseInfo['title']);
            $form[] = $site_input;
            $form[] = array('type'=>'date', 'title'=>'开盘时间', 'name'=>'house_start_time', 'value'=>empty($houseInfo['house_start_time'])?date("Y-m-d"):$houseInfo['house_start_time']);
            $form[] = array('type'=>'text', 'title'=>'面积范围', 'name'=>'house_area_str','value'=>$houseInfo['house_area_str']);
            $form[] = array('type'=>'number', 'title'=>'均价', 'name'=>'price', 'unit'=>'元/㎡','value'=>$houseInfo['price']);
            $form[] = array('type'=>'number', 'title'=>'物管费', 'name'=>'house_wuguan_fee','value'=>$houseInfo['house_wuguan_fee']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'开发商', 'name'=>'house_company','value'=>$houseInfo['house_company']);
            $form[] = array('type'=>'text', 'title'=>'楼盘地址', 'name'=>'house_address','value'=>$houseInfo['house_address']);
            $form[] = array('type'=>'number', 'title'=>'销售电话', 'name'=>'tel','value'=>$houseInfo['tel']);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$houseInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $pics = explode(',',$houseInfo['pics']);
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'房源详情', 'name'=>'content','value'=>$houseInfo['content']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'pic', 'title'=>'房源图片', 'name'=>'pics', 'num'=>2, 'pics'=>$pics);
        }elseif($info['sub_type'] == 'ershou'){
            $res['add_url'] = "https://www.58zltc.com/api.php/House/add?type=2";
            $res['index_url'] = "/pages/index/house/index";

            if(!empty($_GET['infoid'])){
                $houseInfo = M('house')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'标题', 'name'=>'title','value'=>$houseInfo['title']);
            $form[] = $site_input;
            $form[] = array('type'=>'text', 'title'=>'小区名称', 'name'=>'block_name','value'=>$houseInfo['block_name']);
            $form[] = array('type'=>'text', 'title'=>'户型', 'name'=>'house_type','value'=>$houseInfo['house_type']);
            $form[] = array('type'=>'number', 'title'=>'面积', 'name'=>'house_area','value'=>$houseInfo['house_area']);
            $form[] = array('type'=>'number', 'title'=>'总价', 'name'=>'price', 'unit'=>'万元','value'=>$houseInfo['price']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'联系人', 'name'=>'username','value'=>$houseInfo['username']);
            // $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site');
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$houseInfo['tel']);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$houseInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $pics = explode(',',$houseInfo['pics']);
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'房源详情', 'name'=>'content','value'=>$houseInfo['content']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'pic', 'title'=>'房源图片', 'name'=>'pics', 'num'=>2, 'pics'=>$pics);
        }elseif($info['sub_type'] == 'zufang'){
            $res['add_url'] = "https://www.58zltc.com/api.php/House/add?type=3";
            $res['index_url'] = "/pages/index/house/index";

            if(!empty($_GET['infoid'])){
                $houseInfo = M('house')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'标题', 'name'=>'title','value'=>$houseInfo['title']);
            $form[] = $site_input;
            $form[] = array('type'=>'text', 'title'=>'小区名称', 'name'=>'block_name','value'=>$houseInfo['block_name']);
            $form[] = array('type'=>'text', 'title'=>'户型', 'name'=>'house_type','value'=>$houseInfo['house_type']);
            $form[] = array('type'=>'number', 'title'=>'面积', 'name'=>'house_area','value'=>$houseInfo['house_area']);
            $form[] = array('type'=>'number', 'title'=>'租金', 'name'=>'price', 'unit'=>'元/月','value'=>$houseInfo['price']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'联系人', 'name'=>'username','value'=>$houseInfo['username']);
            // $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site');
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$houseInfo['tel']);
            $form[] = array('type'=>'top');
            $tagslist = explode(',',$houseInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $pics = explode(',',$houseInfo['pics']);
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'房源详情', 'name'=>'content','value'=>$houseInfo['content']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'pic', 'title'=>'房源图片', 'name'=>'pics', 'num'=>2, 'pics'=>$pics);
        }elseif($info['sub_type'] == 'common'){
            if($info['pid'] != 0){
                $res['add_url'] = "https://www.58zltc.com/api.php/Info/add?type={$info['pid']}&sub_type={$info['id']}";
                $res['index_url'] = "/pages/index/common/index?id={$info['pid']}";
            }else{
                $res['add_url'] = "https://www.58zltc.com/api.php/Info/add?type={$info['id']}&sub_type=0";
                $res['index_url'] = "/pages/index/common/index?id={$info['id']}";
            }
            if(!empty($_GET['infoid'])){
                $commonInfo = M('info')->where(array('id'=>$_GET['infoid']))->find();
            }
            $form[] = array('type'=>'text', 'title'=>'标题', 'name'=>'title','value'=>$commonInfo['title'] );
            $form[] = $site_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'text', 'title'=>'联系人', 'name'=>'username','value'=>$commonInfo['username']);
            // $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site');
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$commonInfo['tel']);
            $form[] = array('type'=>'top');
            $ctags = array();
            $tagslist = explode(',',$commonInfo['tag']);
            foreach ($tagslist as $key => $value) {
                $ctags[] = array('title'=>$value, 'selected'=>false);
            }
            $tags_input['tags'] = $ctags;
            $pics = explode(',',$commonInfo['pics']);
            $form[] = $tags_input;
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'textarea', 'title'=>'信息详情', 'name'=>'content','value'=>$commonInfo['content']);
            $form[] = array('type'=>'top');
            $form[] = array('type'=>'pic', 'title'=>'信息图片', 'name'=>'pics', 'num'=>2, 'pics'=>$pics);
        }elseif($info['sub_type'] == 'zhaoren'){
            $res['add_url'] = "https://www.58zltc.com/api.php/Pinche/add?type=1";
            $res['index_url'] = "/pages/index/pinche/index";

            if(!empty($_GET['infoid'])){
                $pincheInfo = M('pinche')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'出发地', 'name'=>'start_site','value'=>$pincheInfo['start_site']);
            $form[] = array('type'=>'text', 'title'=>'目的地', 'name'=>'end_site','value'=>$pincheInfo['end_site']);
            $form[] = array('type'=>'date', 'title'=>'出发日期', 'name'=>'go_date', 'value'=>empty($pincheInfo['go_date'])?date("Y-m-d"):$pincheInfo['go_date']);
            $form[] = array('type'=>'time', 'title'=>'出发时间', 'name'=>'go_time', 'value'=>empty($pincheInfo['go_time'])?date("H:i"):$pincheInfo['go_time']);
            $form[] = array('type'=>'number', 'title'=>'座位数', 'name'=>'num','value'=>$pincheInfo['num']);
            $form[] = array('type'=>'top');
            // $form[] = array('type'=>'text', 'title'=>'联系人', 'name'=>'username');
            // $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site');
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$pincheInfo['tel']);
        }elseif($info['sub_type'] == 'zhaoche'){
            $res['add_url'] = "https://www.58zltc.com/api.php/Pinche/add?type=0";
            $res['index_url'] = "/pages/index/pinche/index";

            if(!empty($_GET['infoid'])){
                $pincheInfo = M('pinche')->where(array('id'=>$_GET['infoid']))->find();
            }

            $form[] = array('type'=>'text', 'title'=>'出发地', 'name'=>'start_site','value'=>$pincheInfo['start_site']);
            $form[] = array('type'=>'text', 'title'=>'目的地', 'name'=>'end_site','value'=>$pincheInfo['end_site']);
            $form[] = array('type'=>'date', 'title'=>'出发日期', 'name'=>'go_date', 'value'=>empty($pincheInfo['go_date'])?date("Y-m-d"):$pincheInfo['go_date']);
            $form[] = array('type'=>'time', 'title'=>'出发时间', 'name'=>'go_time', 'value'=>empty($pincheInfo['go_time'])?date("H:i"):$pincheInfo['go_time']);
            $form[] = array('type'=>'number', 'title'=>'乘车人数', 'name'=>'num','value'=>$pincheInfo['num']);
            $form[] = array('type'=>'top');
            // $form[] = array('type'=>'text', 'title'=>'联系人', 'name'=>'username');
            // $form[] = array('type'=>'text', 'title'=>'详细地址', 'name'=>'company_site');
            $form[] = array('type'=>'number', 'title'=>'联系电话', 'name'=>'tel','value'=>$pincheInfo['tel']);
        }

        $res['add_url'] .= "&cid={$info['pid']}&sub_cid={$info['id']}";
        $form[] = array('type'=>'top');
        $form[] = array('type'=>'price', 'title'=>'收费', 'price'=>$wechat['tongcheng_fee']);

        $eq['wid'] = session('wid');
        $top_arr = array("无需置顶");
        $top_arr2 = M("Top")->where($eq)->getField('title',true);
        if($top_arr2){
            $top_arr = array_merge($top_arr,$top_arr2);
        }
        if(empty($_GET['infoid'])){
            $form[] = array('type'=>'picker1', 'title'=>'置顶', 'name'=>'top_fee'
            ,'range'=>$top_arr
            , 'value'=>0);
        }


        $res['form'] = $form;
        $this->ajaxReturn($res);
    }

    public function login(){
        $map['wid'] = session('wid');
        $info = M("Wechat")->where($map)->find();

        $component_appid = C("OPEN_APPID");
    	$appid = $info['appid'];
    	$appsrcret = $info['app_srcret'];
        $token = $this->get_component_access_token();

    	$url = "https://api.weixin.qq.com/sns/component/jscode2session?appid={$appid}&js_code={$_POST['code']}&grant_type=authorization_code&component_appid={$component_appid}&component_access_token={$token}";
    	$res = $this->ihttp_get($url);
    	$td = json_decode($res, true);
    	if($td['errmsg']){
            // dump($td);
  			$arr = array("err_code"=>400,"err_msg"=>$td['errmsg']);
    		$this->ajaxReturn($arr);
    	}
    	$map['openid'] = $td['openid'];
        $user = M("Member")->where($map)->find();
    	if($user){
    		$new['session_key'] = $td['session_key'];
    		M("Member")->where($map)->save($new);
    	}else{
    		$td['wid'] = session('wid');
    		$td['create_time'] = date("Y-m-d H:i:s");
    		M("Member")->add($td);
    	}

    	$arr = array("err_code"=>0, "openid"=>$td['openid'],'user'=>$user,'code'=>($user['nickname']&&$user['headimgurl'])?1:0);
    	$this->ajaxReturn($arr);
    }

    // 设置头像、昵称
    public function user(){
        $map['wid'] = session('wid');
        $map['openid'] = $_GET["openid"];

        $data['nickname'] = I("nickName");
        $data['headimgurl'] = I("avatarUrl");
        $data['gender'] = (I('gender')==1)?1:0;
        M("Member")->where($map)->save($data);

        $arr['code'] = 0;
        $this->ajaxReturn($arr);
    }

    private function getMemberInfo(){

    }

    public function cate(){
        $model = M("Cate");
    	$map = array();
        $map['wid'] = session('wid');
    	if(isset($_GET['id'])){
    		$map['pid'] = $_GET['id'];
    	}
        if($_GET['type']){
            $map['type'] = $_GET['type'];
        }
        if($_GET['need_sub'] == 1){
            $map['can_add'] = 1;
            $list = $model->where($map)->order("sort asc")->select();
            foreach ($list as $key => $value) {
                $eq['pid'] = $value['id'];
                $eq['wid'] = session('wid');
                $sub = $model->where($eq)->order("sort asc")->select();
                foreach ($sub as $k => $v) {
                    if($value['need_id']){
                        $sub[$k]['url'] = "{$v['add_url']}?id={$v['id']}";
                    }else{
                        $sub[$k]['url'] = $v['add_url'];
                    }
                }
                $list[$key]['url'] = $value['add_url'];
                $list[$key]['sub'] = $sub;
            }
        }else{
            $list = M("Cate")->where($map)->order("sort asc")->select();
            foreach ($list as $key => $value) {
                if($value['need_id']){
                    $list[$key]['url'] = "{$value['url']}?id={$value['id']}";
                }elseif($value['type'] == 'shop'){
                    $list[$key]['url'] = "list?id={$value['id']}";
                }
            }
        }
        $arr = array();
        if($list){
            array_push($list, $arr);
        }

    	$this->ajaxReturn($list);
    }

    public function addFormId(){
        if($_POST['openid'] != 'undefined'){
            $data['openid'] = I("post.openid");
            $data['form_id'] = I("post.form_id");
            $data['max_num'] = $_POST['type'] == 'pay'?3:1;
            $data['used_num'] = 0;
            $data['end_time'] = date("Y-m-d H:i:s", strtotime("+7 days"));
            M("Formid")->add($data);
        }
    }

    public function upload(){
    	$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     3145728 ;// 设置附件上传大小
		$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg', 'mp4');// 设置附件上传类型
		$upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
		$upload->savePath  =      ''; // 设置附件上传（子）目录
		// 上传文件 
		$info   =   $upload->upload();
        // $str = "ffmpeg -i /www/web/zltc_qingyuntongcheng_com/public_html/Uploads/2017-12-14/5a323faca6d92.mp4  -y -f mjpeg -ss 3 -t 1 /www/web/zltc_qingyuntongcheng_com/public_html/Uploads/2017-12-14/test.jpg";
		if(!$info) {// 上传错误提示错误信息
			$arr = array("err_code"=>400,"err_msg"=>$upload->getError());
    		$this->ajaxReturn($arr);
		}else{// 上传成功 获取上传文件信息
			$file = $info['file'];
            $file_name = $file['savepath'].$file['savename'];
            $file_img_name = "";
            if(preg_match('/mp4/', $file['type'])){
                $file_img_name = str_replace('mp4', 'jpg', $file_name);
                shell_exec("ffmpeg -i /www/web/zltc_qingyuntongcheng_com/public_html/Uploads/{$file_name}  -y -f mjpeg -ss 3 -t 1 /www/web/zltc_qingyuntongcheng_com/public_html/Uploads/{$file_img_name}");
            }
			$arr = array("err_code"=>0,"file_name"=>$file_name, "file_img_name"=>$file_img_name);
    		$this->ajaxReturn($arr);
		}
    }
    public function uploadVideo(){
        if($_FILES['file']){
            $file = $_FILES['file'];
            // 要上传图片的本地路径
            $filePath = $file['tmp_name'];
            $ext = pathinfo($file['name'], PATHINFO_EXTENSION);  //后缀
            // 上传到七牛后保存的文件名
            $key =substr(md5($filePath) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext;
            vendor('qiniu.autoload');
            // 需要填写你的 Access Key 和 Secret Key
            $accessKey = C('Access_Key');
            $secretKey = C('Secret_Key');
            // 构建鉴权对象
            $auth = new Auth($accessKey, $secretKey);
            // 要上传的空间
            $bucket = C('Bucket');
            $domain = C('Domain');
            $token = $auth->uploadToken($bucket);
            // 初始化 UploadManager 对象并进行文件的上传
            $uploadMgr = new UploadManager();
            // 调用 UploadManager 的 putFile 方法进行文件的上传
            list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);

            if ($err !== null) {
                $data['err'] = 1;
                $data['msg'] = $err;
                $data['data'] ='';
                $this->ajaxReturn($data);
            } else {
                //返回图片的完整URL
                $data['err'] = 0;
                $data['msg'] = '上传完成';
                $data['data']['domain'] = $domain.$ret['key'];
                $data['data']['thumb'] = $domain.$ret['key'].'?vframe/png/offset/1';
                $this->ajaxReturn($data);
            }
        }else{
            $data = array();
            $data['err'] = 1;
            $data['msg'] = '请重新选取视频';
            $data['data'] ='';
            $this->ajaxReturn($data);
        }
    }
    public function uploadImage(){
        if($_FILES['file']){
            $file = $_FILES['file'];
            // 要上传图片的本地路径
            $filePath = $file['tmp_name'];
            $ext = pathinfo($file['name'], PATHINFO_EXTENSION);  //后缀
            // 上传到七牛后保存的文件名
            $key =substr(md5($filePath) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext;
            vendor('qiniu.autoload');
            // 需要填写你的 Access Key 和 Secret Key
            $accessKey = C('Access_Key');
            $secretKey = C('Secret_Key');
            // 构建鉴权对象
            $auth = new Auth($accessKey, $secretKey);
            // 要上传的空间
            $bucket = C('Bucket');
            $domain = C('Domain');
            $token = $auth->uploadToken($bucket);
            // 初始化 UploadManager 对象并进行文件的上传
            $uploadMgr = new UploadManager();
            // 调用 UploadManager 的 putFile 方法进行文件的上传
            list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
            $data = array();
            if ($err !== null) {
                $data['err'] = 1;
                $data['msg'] = $err;
                $data['data'] ='';
                $this->ajaxReturn($data);
            } else {
                //返回图片的完整URL
                $data['err'] = 0;
                $data['msg'] = '上传完成';
                $data['domia'] = $domain;
                $data['key'] = $ret['key'];
                $data['data']['domain'] = $domain."/".$ret['key'];
                $this->ajaxReturn($data);
            }
        }else{
            $data = array();
            $data['err'] = 1;
            $data['msg'] = '请重新选取图片';
            $data['data'] ='';
            $this->ajaxReturn($data);
        }
    }
    public function uploadImage2(){
        if($_FILES['file']){
            $file = $_FILES['file'];
            // 要上传图片的本地路径
            $filePath = $file['tmp_name'];
            $ext = pathinfo($file['name'], PATHINFO_EXTENSION);  //后缀
            // 上传到七牛后保存的文件名
            $key =substr(md5($filePath) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext;
            vendor('qiniu.autoload');
            // 需要填写你的 Access Key 和 Secret Key
            $accessKey = C('Access_Key');
            $secretKey = C('Secret_Key');
            // 构建鉴权对象
            $auth = new Auth($accessKey, $secretKey);
            // 要上传的空间
            $bucket = C('Bucket');
            $domain = C('Domain');
            $token = $auth->uploadToken($bucket);
            // 初始化 UploadManager 对象并进行文件的上传
            $uploadMgr = new UploadManager();
            // 调用 UploadManager 的 putFile 方法进行文件的上传
            list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
            $data = array();
            if ($err !== null) {
                $data['err'] = 1;
                $data['msg'] = $err;
                $data['data'] ='';
                $this->ajaxReturn($data);
            } else {
                //返回图片的完整URL
                $data['err'] = 0;
                $data['msg'] = '上传完成';
                $data['domia'] = $domain;
                $data['key'] = $ret['key'];
                $data['data']['domain'] = $domain."/".$ret['key'];
                $this->ajaxReturn($data);
            }
        }else{
            $data = array();
            $data['err'] = 1;
            $data['msg'] = '请重新选取图片';
            $data['data'] ='';
            $this->ajaxReturn($data);
        }
    }

    //获取小程序的模板消息
    public function gettemplate()
    {
        $token = $this->get_access_token_mp();
        $post_data =array(
            'offset' => 0,
            'count' => 20
        );
        $url = "https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=".$token;
        $res = $this->ihttp_post($url,json_encode($post_data));
        $td = json_decode($res, true);
    }
    //发送模板消息测试
    public function sendtemplate()
    {
        $access_token = $this->get_access_token_mp();
        $data = $_POST;
        $touser = "oRVj50L-3jTgEqslDeC7sz8lc-Ds";
        $template_id = "GFnTfRRmlxitBmBZjhnUtP1gofufXI1iUGe88f-ByX4";
        $page = "pages/index/index";
        $form_id = I('formid');

        $keyword1 = "蓝海";//酒店名称
        $fee = "linyi.China";  //地点
        if(empty($keyword1)){
            exit('empty activity message!');
        }
        $value = array(
            "keyword1"=>array(
                "value"=>$keyword1,
                //"value"=>'woshihaoren',
                "color"=>"#4a4a4a"
            ),
            "keyword2"=>array(
                "value"=>'2018-04-25', //预订时间
                "color"=>"#9b9b9b"
            ),
            "keyword3"=>array(
                "value"=>"￥5.0",//金额
                "color"=>"#9b9b9b"
            ),
            "keyword4"=>array(
                "value"=>$fee,//地点
                "color"=>"#9b9b9b"
            ),
            "keyword5"=>array(
                "value"=>'2018-04-25',//入住时间
                "color"=>"#9b9b9b"
            ),
            "keyword6"=>array(
                "value"=>'2018-04-26',//离店时间
                "color"=>"#9b9b9b"
            ),
            "keyword7"=>array(
                "value"=>'大床房',//房间类型
                "color"=>"#9b9b9b"
            ),
            "keyword8"=>array(
                "value"=>'2人',//入住人
                "color"=>"#9b9b9b"
            ),
            "keyword9"=>array(
                "value"=>'20510',//房间数量
                "color"=>"red"
            )
        );

        $url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='.$access_token;
        $dd = array();
        //$dd['access_token']=$access_token;
        $dd['touser']=$touser;
        $dd['template_id']=$template_id;
        $dd['page']=$page;  //点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,该字段不填则模板无跳转。
        $dd['form_id']=$form_id;

        $dd['data']=$value;                        //模板内容，不填则下发空模板

        $dd['color']='';                        //模板内容字体的颜色，不填默认黑色
        //$dd['color']='#ccc';
        $dd['emphasis_keyword']='';    //模板需要放大的关键词，不填则默认无放大
        //$dd['emphasis_keyword']='keyword1.DATA';

        //$send = json_encode($dd);   //二维数组转换成json对象

        /* curl_post()进行POST方式调用api： api.weixin.qq.com*/
        $result = $this->ihttp_post($url,json_encode($dd));
        $result = json_decode($result,true);
        if($result){
            echo json_encode(array('errcode'=>$result['errcode'],'msg'=>$result['errmsg']));
        }else{
            echo json_encode(array('errcode'=>$result['errcode'],'msg'=>$result['errmsg']));
        }
    }

    private function get_component_access_token(){
        $token = S("component_access_token");
        if($token){
            return $token;
        }
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";

        $post_data = array(
            "component_appid"=>C("OPEN_APPID"),
            "component_appsecret"=>C("OPEN_APPSECRET"),
            "component_verify_ticket"=>S("component_verify_ticket"));
        $json = json_encode($post_data);
        $res = $this->ihttp_post($url, $json);
        $td = json_decode($res, true);
        if($td['component_access_token']){
            S("component_access_token", $td['component_access_token'], $td['expires_in'] - 120);
            return $td['component_access_token'];
        }else{
            return false;
        }
    }

    //查数据获得分类检索
    public function getCate(){
        $model = M("Cate");
        $map = array();
        $map['wid'] = session('wid');
        if(isset($_GET['id'])){
            $map['pid'] = $_GET['id'];
        }
        if($_GET['type']){
            $map['type'] = $_GET['type'];
        }
        if($_GET['need_sub'] == 1){
            $map['can_add'] = 1;
            $list = $model->where($map)->order("sort asc")->select();
            foreach ($list as $key => $value) {
                $eq['pid'] = $value['id'];
                $sub = $model->where($eq)->order("sort asc")->select();
                foreach ($sub as $k => $v) {
                    if($value['need_id']){
                        $sub[$k]['url'] = "{$v['add_url']}?id={$v['id']}";
                    }else{
                        $sub[$k]['url'] = $v['add_url'];
                    }
                }
                $list[$key]['url'] = $value['add_url'];
                $list[$key]['sub'] = $sub;
            }
        }else{
            $list = M("Cate")->where($map)->order("sort asc")->select();
            foreach ($list as $key => $value) {
                if($value['need_id']){
                    $list[$key]['url'] = "{$value['url']}?id={$value['id']}";
                }elseif($value['type'] == 'shop'){
                    $list[$key]['url'] = "list?id={$value['id']}";
                }
            }
        }
        //处理list返回需要数组
        $arr['title'] = '全部分类';
        $arr['is_show'] = false;
        $arr['list'] = array();
        $arr['list'][0] = array('id'=> 0,'value'=>'全部分类', 'is_selected'=>true);
        foreach($list as $k=>$v) {
            $arr['list'][] = array(
                'id' =>         $v['id'],
                'value' =>      $v['title'],
                'is_selected'=> false
            );
        }
        return $this->ajaxReturn($arr);
    }

    //保存商户广告信息
    public function uploadShopImg () {
        $request = file_get_contents('php://input');
        $arr = json_decode($request,true);
        $map = array();
        $shop = M('shop')->where(['shop_id' => $arr['shop_id']])->find();
        if(!$shop){
            $msg = 0;
            return $this->ajaxReturn($msg);
        }
        //$map['shop_link'] = $arr['link'];
        //$map['shop_advimg'] = $arr['file_name'];
        $shop_banner = implode(",",$arr['file_name2']);//店铺轮播
        $pics = implode(",",$arr['file_name']);//店铺相册
        if($arr['link']) {
            $map['shop_video'] = $arr['link'];//店铺视频
        }

        $map['shop_banner'] = $shop_banner ? $shop_banner : $shop['shop_banner'];
        $map['pics'] = $pics ? $pics : $shop['pics'];

        $row = M('shop')->where(['shop_id' => $arr['shop_id']])->save($map);
        $row ? $msg = 1 : $msg = 0;
        return $this->ajaxReturn($msg);
    }
    //获取单个商户信息
    public function getShopInfo () {
        $info = M('shop')->where(['shop_id' => $_GET['id']])->find();
        if($info['shop_banner']){
            $info['shop_banner'] = explode(",",$info['shop_banner']);
        }
        if($info['pics']){
            $info['pics'] = explode(",",$info['pics']);
        }
        return $this->ajaxReturn($info);
    }
    //获取外卖店铺id
    public function getTakeoutid()
    {
        $openid = I('openid');
        $eq['openid'] = $openid;
        $eq['wid'] = session('wid');
        $store = M('takeout_store')->where($eq)->find();
        $this->ajaxReturn($store);
    }
    //获取开屏广告
    public function getAdvShop () {
        //1.首页 2.好店 3.同城圈
        $position          = I('pos');
        $wid               = session('wid');
        $where['wid']      = $wid;
        $where['status']   = 1;
        $where['position'] = $position;
        $adv = [];
        $shouye = M("adv_shop")->where($where)->find();
        //链接类型 1:小程序内部跳转链接
        if ($shouye['url_type'] == 1) {
            //1:跳转店铺
            if ($shouye['type'] == 1) {
                $shouye_shop = M('shop')->where(['wid' => $wid, 'shop_id' => $shouye['shop_id']])->find();
                //建材
                if ($shouye_shop['type'] == 'jiancai') {
                    $adv['url'] = "/pages/shop/jiancai/detail?shop_id=".$shouye['shop_id'];
                }
                //教育
                elseif ($shouye_shop['type'] == 'jiaoyu') {
                    $adv['url'] = "/pages/shop/jiaoyu/detail?shop_id=".$shouye['shop_id'];
                }
                //汽车
                elseif ($shouye_shop['type'] == 'car') {
                    $adv['url'] = "/pages/shop/car/detail?shop_id=".$shouye['shop_id'];
                }
                //通用
                else {
                    $adv['url'] = "/pages/shop/detail?shop_id=".$shouye['shop_id'];
                }
            }
            //2:跳转商品
            elseif ($shouye['type'] == 2) {
                $adv['url'] = "/pages/shop/goods/detail?id=".$shouye['goods_id'];
            }
            //3：跳转资讯
            elseif ($shouye['type'] == 3) {
                $adv['url'] = "/pages/quan/news/detail?id=".$shouye['news_id'];
            }
            $adv['jump_type'] = 1;
        }
        //2：跳转网页链接
        elseif ($shouye['url_type'] == 2) {
            $adv['url'] = $shouye['url'];
            $adv['jump_type'] = 2;
        }
        $adv['img'] = $shouye['imgurl'];
        $this->ajaxReturn($adv);
    }

    //获取资讯分类列表
    public function cateList(){
        $map = array();
        $map['status'] = 1;
        $map['wid'] = session('wid');
        $list = M("index_cate")->where($map)->order('add_time desc')->select();
        $arr = array();
        $arr['name'] = '推荐';
        $arr['url'] = 'index';
        array_unshift($list,$arr);
        $this->ajaxReturn($list);
    }

    //
    public function savePersonalInfo () {
        $request = file_get_contents('php://input');
        $arr = json_decode($request,true);
        $title = [
            'user_age' => '年龄',
            'user_monologue' => '个人独白',
            'user_condition' => '交友条件',
            'user_label' => '个性标签',
            'user_wechat' => '微信号',
            'user_qq' => 'QQ',
            'user_mobile' => '手机号',
            'user_ismarry' => '婚姻状况',
            'user_height' => '身高',
            'user_education' => '学历',
            'user_income' => '收入',
            'user_occupation' => '职业',
            'user_hobby' => '我的爱好',
            'user_place' => '所在地',
            'user_hometown' => '故乡',
            'gender' => '性别'
        ];
//        foreach ($arr as $k => $v) {
//            if (empty($v)) {
//                $this->ajaxReturn(['error' => 1, 'msg' => $title[$k].' 未填写']);
//            }
//        }
        if ($arr['user_age'] > 120 || $arr['user_age'] < 12) {
            $this->ajaxReturn(['error' => 1, 'msg' => '年龄需在12到120之间']);
        }
        $user_wechat = $arr['user_wechat'];
        $suc_user_wechat = preg_match('/^[a-zA-Z0-9_]+$/', $user_wechat);
        if (!$suc_user_wechat) {
            $this->ajaxReturn(['error' => 1, 'msg' => '微信号格式错误']);
        }
//        if (strlen($arr['user_qq']) >15 || strlen($arr['user_qq']) < 5 || !is_numeric($arr['user_qq'])) {
//            $this->ajaxReturn(['error' => 1, 'msg' => 'QQ号格式错误']);
//        }
//        if(!preg_match("/^1[34578]{1}\d{9}$/",$arr['user_mobile']) || !is_numeric($arr['user_mobile'])){
//            $this->ajaxReturn(['error' => 1, 'msg' => '手机号格式错误']);
//        }

        //插入数据
        $row = M('member')->where(['openid' => $_GET['openid'], 'wid' => session('wid')])->save($arr);

        $row ? $this->ajaxReturn(['error' => 0, 'msg' => '提交成功']) : $this->ajaxReturn(['error' => 1, 'msg' => '未修改或网络繁忙']);
    }

    //
    public function getPersonalInfo () {
        $arr = M('member')->where(['openid' => $_GET['openid'], 'wid' => session('wid')])->select();
        foreach ($arr as $k  => $v) {
            (empty($v) || $v == 'null') ? $arr[$k] = '未填写' : '';
        }
        $this->ajaxReturn($arr);
    }

    public function getMyfollows () {
        $listAll = [];
        $where['a.openid'] = I('openid');
        //关注的人
        $list = M('quan_follow')->alias('a')
                                ->field('a.last_time, b.nickname, b.headimgurl, b.user_age, b.gender, b.openid')
                                ->join('tp_member b on a.follow_openid = b.openid')
                                ->where($where)
                                ->order('a.last_time desc')
                                ->limit('0, 50')
                                ->select();
        $listAll['man'] = $list;
        //关注的店铺
        $shop = M('shop_follow')->alias('a')
                                ->field('a.last_time as lasttime, b.*')
                                ->join('tp_shop b on a.shop_id = b.shop_id')
                                ->where($where)
                                ->order('a.last_time desc')
                                ->limit('0, 50')
                                ->select();
        $listAll['shop'] = $shop;
        //总数
        $listAll['length'] = count($list) + count($shop);
        $this->ajaxReturn($listAll);
    }

    public function getMyPageInfo () {
        $list = [];
        $wid = session('wid');
        //开通同城卡的人数
        $tcardNum = M('card_log')->where(['is_pay' => 1, 'wid' => $wid])->count();
        $list['tcNum'] = $tcardNum;
        //待评价
        $map = array();
        $map['wid'] = session('wid');
        $map['is_pay'] = 1;
        $map['openid'] = $_GET['openid'];
        $map['status'] = 2;
        $listP = M("Order")->where($map)->select();
        $pingNum = 0;
        foreach ($listP as $k => $v) {
            $row = M("shop_evaluate")->where(['order_id' => $v['id']])->find();
            $row ? '' : $pingNum++;
        }
        $list['witePingNum'] = $pingNum;
        //推荐活动商品
        $whereH['a.is_kan']   = ['neq', 0];
        $whereH['a.is_pin']   = ['neq', 0];
        $whereH['a.is_qiang'] = ['neq', 0];
        $whereH['_logic']     = 'or';
        $whereHuo['_complex'] = $whereH;
        $whereHuo['a.wid']    = session('wid');
        $whereHuo['a.status'] = 1;
        $listHuo =  M("Goods")->alias('a')
                              ->field('a.*, b.join_end_time, b.cate')
                              ->join('tp_shop b on a.shop_id = b.shop_id')
                              ->where($whereHuo)
                              ->where(['b.join_end_time' => ['gt', date('Y-m-d H:i:s', time())]])
                              ->order("last_time desc")
                              ->limit(0, 8)
                              ->select();
        $list['listHuo'] = $listHuo;
        //是否开通同城卡
        $isHaveTCared = M('card_log')->where(['wid' => session('wid'), 'openid' => $_GET['openid'], 'is_pay'=>1,'end_time' => ['gt', date('Y-m-d H:i:s', time())]])->find();
        $list['isHaveTCared'] = $isHaveTCared ? 1 : 0;

        //我的上级
        $user = getMember(session('wid'),I('openid'));
        $agent = M('member')->where(['mid'=>$user['agent']])->find();
        $list['agentName'] = $agent?$agent['nickname']:'暂无';
        //未体现佣金
        $list['commission'] = $user['commission_wite'];
        $this->ajaxReturn($list);
    }
    //验证核销信息
    public function heXiaoInfo () {
        $str    = I('scenestr');
        $arr    = explode(',', $str);
        $openid = $arr[0];
        $wid    = $arr[1];
        $row    = M('card_log')->where(['wid' => $wid, 'openid' => $openid, 'end_time' => ['gt', time()], 'is_pay' => 1])->find();
        if ($row) {
            $this->ajaxReturn(['error' => 0, 'msg' => '用户是本平台会员']);
        } else {
            $this->ajaxReturn(['error' => 1, 'msg' => '用户不是本平台会员!']);
        }
    }
    //建立分销等级
    public function createGrade () {
        $data = [];
        $sess     = session('wid');
        $fWid     = I('fWid');
        $fOpenid  = I('fOpenid');//上级
        $myOpenid = I('myOpenid');//我
        $my       = M('member')->where(['openid' => $myOpenid, 'wid' => session('wid')])->find();
        //产生推荐关系
        if ($fOpenid == $myOpenid || $fWid != session('wid')) {
            return false;
        }
        //上级
        $f = M('member')->where(['openid' => $fOpenid, 'wid' => $fWid])->find();
        if(!$f || !$my){
            return false;
        }
        //上级同城卡是否有效
        $isHaveTCared = M('card_log')->where(['wid' => $sess, 'openid' => $fOpenid,'is_pay'=>1, 'end_time' => ['gt', date('Y-m-d H:i:s', time())]])->find();
        if(!$isHaveTCared){
            return false;
        }
        //不可重复推荐
        if($my['agent']){
            return false;
        }

        //是否有下级
        $haveSonLv = M('member')->where(['agent' => $my['mid'], 'wid' => $sess])->select();
        if (!$haveSonLv) {
            //所有上级
            if ($f['path']) {
                $path = $f['path'].','.$f['mid'];
            } else {
                $path = $f['mid'];
            }
            //团队分红逻辑推荐关系，不是队长和副队长,并且我没有队长
            if($f['is_leader'] && $my['is_team_leader']!= 1 && $my['is_leader2']!= 1&& $my['team_leader']== 0){
                $data['team_leader'] = $f['mid'];
            }
            //上级
            $data['agent'] = $f['mid'];
            $data['path'] = $path;
            $row_1 = M('member')->where(['openid' => $myOpenid, 'wid' => session('wid')])->save($data);
            if ($row_1) {
                $this->ajaxReturn(['error' => 0, 'msg' => '被推荐成功']);
            } else {
                $this->ajaxReturn(['error' => 1, 'msg' => '网络繁忙']);
            }
        }
    }

    public function getGlobaWid () {
        $this->ajaxReturn(session('wid'));
    }

    /*
     * 创建店员关系
     *
     * */
    public function createClerk () {
        //店主
        $openid = $_GET['openid'];
        //店员
        $c_openid = $_GET['c_openid'];
        //店员是否有店铺
        $map['wid'] = session('wid');
        $map['openid'] = $_GET['c_openid'];
        $map['is_pay'] = 1;
        $shop_arr = M("Shop")->where($map)->find();
        if ($shop_arr) {
            $this->ajaxReturn(['error' => 1, 'msg' => '你已有店铺!']);
        }
        //建立关系
        $row = M('member')->where(['openid' => $c_openid, 'wid' => session('wid')])->save(['shopkeeper_openid' => $openid]);
        if ($row) {
            $this->ajaxReturn(['error' => 0, 'msg' => '你已成为店员']);
        } else {
            $this->ajaxReturn(['error' => 1, 'msg' => '已添加或网络忙']);
        }
    }

    /*
     * 添加积分商品
     *
     * */
    public function getAddIntForm(){
        if($_GET['id']){
            $intGoodInfo = M('credit_goods')->where(['id' => $_GET['id']])->find();
        }
        $info = M('shop')->where(['openid'=>I('openid'),'status'=>1,'is_pay'=>1,'join_end_time'=>['gt', date('Y-m-d H:i:s', time())]])->order('create_time desc')->find();
        $shop = M('shop_card_yh')->where(['shop_id'=>$info['shop_id'],'status'=>1])->find();//是否开通和同城卡
        $pics = array();

        $store = M('takeout_store')->where(['openid'=>I('openid')])->find();

        $res['store_id'] = $info['shop_id'];
        $res['add_url'] = "https://www.58zltc.com/api.php/Shop/addIntGoods";
        $form[] = array('type'=>'number', 'title'=>'排序', 'name'=>'order_num', 'value' => $intGoodInfo['order_num']);
        $form[] = array('type'=>'text', 'title'=>'商品标题', 'name'=>'name', 'value' => $intGoodInfo['name']);
        //$form[] = array('type'=>'picker1', 'title'=>'所属分类', 'name'=>'type_id','range'=>$typename, 'value'=>0);
        $form[] = array('type'=>'pic', 'title'=>'商品图片', 'name'=>'img','num'=>1, 'pics'=>[$intGoodInfo['img'] ? $intGoodInfo['img'] : '']);
        $form[] = array('type'=>'top');
        $form[] = array('type'=>'digit', 'title'=>'商品原价', 'name'=>'old_price', 'value' => $intGoodInfo['old_price']);
        $form[] = array('type'=>'number', 'title'=>'每人兑换次数', 'name'=>'chance', 'value' => $intGoodInfo['chance']);
        $form[] = array('type'=>'number', 'title'=>'每天兑换次数', 'name'=>'chanceday', 'value' => $intGoodInfo['chanceday']);
        $form[] = array('type'=>'digit', 'title'=>'消耗积分', 'name'=>'rate1', 'value' => $intGoodInfo['rate1']);
        //$form[] = array('type'=>'digit', 'title'=>'消耗金额', 'name'=>'rate2', 'value' => $intGoodInfo['rate2']);
        $form[] = array('type'=>'textarea', 'title'=>'商品详情', 'name'=>'content', 'value' => $intGoodInfo['content']);
        $form[] = array('type'=>'number', 'title'=>'库存', 'name'=>'stock', 'value' => $intGoodInfo['stock']);
        $form[] = array('type' => 'checkbox', 'title' => '是否暂停', 'name' => 'is_stop', 'checked'=> $intGoodInfo['is_stop'] == 1 ? true : false, 'value' => $intGoodInfo['is_stop']);

//            $form[] = array('type'=>'number', 'title'=>'设置月销售数量', 'name'=>'sit_ys_num');
//            $form[] = array('type'=>'top');
//            $form[] = array('type'=>'picker1', 'title'=>'菜品选项', 'name'=>'dishes_type','range'=>['外卖','店内','店内+外卖'], 'value'=>2);
//            $form[] = array('type'=>'digit', 'title'=>'餐盒费', 'name'=>'box_fee');
//            $form[] = array('type'=>'checkbox', 'title'=>'招牌', 'name'=>'signature','checked'=>true, 'value'=>1);
//            $form[] = array('type'=>'checkbox', 'title'=>'是否上架', 'name'=>'is_shelves','checked'=>true, 'value'=>1);
//            $form[] = array('type'=>'top');
//            if($shop) {
//                $form[] = array('type' => 'checkbox', 'title' => '是否参与分销', 'name' => 'is_commission', 'checked'=>true, 'value' => 1);
//                $form[] = array('type' => 'picker1', 'title' => '分销类型', 'name' => 'commission_type', 'range' => ['外卖', '店内', '店内+外卖'], 'value' => 2);
//                $form[] = array('type' => 'digit', 'title' => '店内一级佣金比列(%)', 'name' => 'commission_one_in');
//                $form[] = array('type' => 'digit', 'title' => '店内二级佣金比列(%)', 'name' => 'commission_two_in');
//                $form[] = array('type' => 'digit', 'title' => '外卖一级佣金比列(%)', 'name' => 'commission_one_out');
//                $form[] = array('type' => 'digit', 'title' => '外卖二级佣金比列(%)', 'name' => 'commission_two_out');
//                $form[] = array('type'=>'top');
//            }
//            $form[] = array('type'=>'textarea', 'title'=>'商品简介', 'name'=>'details');



        /* if($shop){
             $form[] = array('type'=>'digit', 'title'=>'会员价', 'name'=>'vip_price', 'value'=>$info['vip_price']);
             //商品参与分销以及佣金
             $form[] = array('type'=>'checkbox', 'title'=>'参与分销', 'name'=>'is_commission', 'value'=>0, 'checked'=>false);
             $form[] = array('type'=>'number', 'title'=>'一级佣金比例(%)', 'name'=>'commission_one', 'value'=>$info['commission_one']);
             $form[] = array('type'=>'number', 'title'=>'二级佣金比例(%)', 'name'=>'commission_two', 'value'=>$info['commission_two']);
         }
         $form[] = array('type'=>'number', 'title'=>'库存', 'name'=>'stock');
         $form[] = array('type'=>'top');
         $form[] = array('type'=>'checkbox', 'title'=>'开启限购', 'name'=>'is_xian', 'value'=>0, 'checked'=>false);
         $form[] = array('type'=>'number', 'title'=>'每人限购件数', 'name'=>'max_num', 'value'=>$info['max_num']);
         $form[] = array('type'=>'top');
         $form[] = array('type'=>'pic', 'title'=>'商品图片', 'name'=>'pics', 'num'=>2, 'pics'=>$pics);
         $form[] = array('type'=>'top');
         $form[] = array('type'=>'textarea', 'title'=>'商品简介', 'name'=>'content');*/
        $res['form'] = $form;
        $res['index_url'] = "/pages/mine/shop/goods/list2";
        $this->ajaxReturn($res);
    }
}